Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 11489 - Integer Game / integergame.cpp
blobcc21f2392d783c4a8345a22a3cc7d15f8b49c585
1 #include<iostream>
2 #include<string>
3 #include<stdio.h>
4 using namespace std;
5 int main(){
6 string bigint;
7 int cases=1;
8 int mod;
9 int n3;
10 int n;
11 cin>>n;
12 string winner="TS";
13 while(n-- && cin>>bigint){
14 printf("Case %d: ",cases++);
15 mod=0;
16 n3=0;
17 for(int i=0;i<bigint.size();++i){
18 mod=(mod+(bigint[i]-'0')%3)%3;
19 if((bigint[i]-'0')%3==0) ++n3;
21 bool empiezan=false;
22 if(mod!=0){
23 for(int i=0;i<bigint.size();++i){
24 if((bigint[i]-'0')%3==mod){
25 ++n3;
26 empiezan=true;
27 break;
30 }else{
31 empiezan=true;
33 if(empiezan) cout<<winner[n3%2]<<endl;
34 else cout<<"T"<<endl;
36 return 0;